package com.scott.ch300.lambda.ch05;

import org.junit.Test;

import java.io.PrintStream;
import java.util.Comparator;
import java.util.function.BiFunction;
import java.util.function.Consumer;

/**
 * @author 黄后林
 * @version 1.0
 * @note
 * @date 2022-06-28 21:50:42
 */
public class StudyLambda {


    @Test
    public void test1(){
        PrintStream printStream = System.out;
        // 对象::动态方法
        Consumer con = printStream::println;
        con.accept("123456");

        // 上面3句话相当于下面的1句话
        System.out.println("123456");


        Consumer con1=(x)-> System.out.println(x);
        con1.accept("hello");

        Consumer con2=System.out::println;
        con2.accept("scott");

    }

    @Test
    public void test2(){
        // 类::静态方法
        // 参数列表和返回类型要一样
        Comparator<Integer> com =Integer::compare;
        System.out.println(com.compare(20,20));

    }

    @Test
    public void test3(){
        // 类::动态方法
        // 参数列表和返回类型要一样
        BiFunction<String, Object, Boolean> bi = String::equals;
        Boolean rs = bi.apply("1234", new String("123"));
        System.out.println(rs);
    }
}
